// 比较含退格的字符串
class Solution {
    public boolean backspaceCompare(String s, String t) {
        return changeStr(s).equals(changeStr(t));
    }

    public String changeStr(String s) {
        StringBuffer ret = new StringBuffer();
        char[] tmp = s.toCharArray(); // 数组模拟栈结构
        for (int i = 0; i < tmp.length; i++) {
            if (tmp[i] != '#') {
                ret.append(tmp[i]); // 入栈
            } else {
                if (ret.length() > 0)
                    ret.deleteCharAt(ret.length() - 1); // 出栈
            }
        }
        return ret.toString();
    }
}